< previous page page_373 next page >

Page 373
e10a6a0a59f035e870d90cca05b85fce.gif
    If ww_aspect > view_aspect Then
        ' The world window is too tall and thin.
        ' Make it wider.
        ww_wid = ww_hgt / view_aspect
    Else
        ' The world window is too short and wide.
        ' Make it taller.
        ww_hgt = view_aspect * ww_wid
    End If
End Sub
As is the case with fixed levels of magnification, once you have adjusted the world window, you must decide where to place it. As before, the most sensible choice is to center it over its old position. If you are enlarging the world window, you can also check to see if the new world window extends far beyond the edge of the picture. If it does, you can move the window so that it displays more of the picture and less empty space.
Selecting a Constrained Region
A third method that ensures the world window and viewport have the same aspect ratios is to allow the user to select only regions of the proper shape. You can use a rubber band technique to allow the user to select a region as before. As the user stretches the region, however, you adjust the aspect ratio of the region so that it always matches the aspect ratio of the viewport.
When you use the previous methods, you sometimes need to enlarge the world window so that its aspect ratio matches that of the viewport. This means parts of the picture that were not explicitly selected by the user are included in the new world window. The new, constrained method has the advantage that the user sees exactly what region will be displayed.
On the other hand, with the previous methods, the region the user selects is centered in the viewport. If the user selects a single object of interest, that object is placed in the viewport's center. The constrained method makes it a bit harder for the user to center the viewport over a specific region. To make the constrained rubber band box include an area of interest, the user may need to include other parts of the picture that are less interesting. When the user finishes the selection, the most important part of the picture may not be centered in the viewport.
The Visual Basic code to manage this sort of constrained rubber band box is similar to the code for normal rubber band boxes used by program RubrBox described in Chapter 1, Visual Basics. The major difference is in the MouseMove and MouseUp events. Before these routines use the new coordinates for the rectangle's corner, they call subroutine AdjustAspect to figure out what dimensions the newly selected region should have. They then use these dimensions to adjust the corners of the selected region before drawing the rubber band box.
The AdjustAspect routine used by these event handlers is also a little different from the one presented earlier. To allow the user to create a rubber band box to the left or above the initial mouse position, this version of AdjustAspect must handle the case where the

 
< previous page page_373 next page >